<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>评价列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/oksub.css">
    <script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
    <style>
        #menu-options {
            position: fixed;
            top: 10px; /* 距离顶部的距离 */
            right: 10px; /* 距离右侧的距离 */
            background-color: #fff; /* 背景颜色 */
            padding: 10px;
            border: 1px solid #ccc; /* 边框 */
            font-size: 14px; /* 字体大小 */
        }
        img{
            width: 140px;
            height: 40px;
        }
    </style>
</head>
<body>
<div class="ok-body">

    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 ok-search">
            <input class="layui-input" placeholder="菜名" autocomplete="off" id="food_name" name="food_name">
            <input class="layui-input" placeholder="用户" autocomplete="off" id="nickname" name="nickname">
            <button class="layui-btn" lay-submit="" lay-filter="search">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script>
    layui.use(["table", "form", "laydate", "okLayer", "okUtils", "okMock"], function () {
        let table = layui.table;
        let form = layui.form;
        let util = layui.util;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        let okMock = layui.okMock;
        okLoading.close();
        util.fixbar({});

        laydate.render({elem: "#startTime", type: "datetime"});
        laydate.render({elem: "#endTime", type: "datetime"});

        let articleTable = table.render({
            elem: "#tableId",
            url: okMock.api.reviewslist,
            limit: 10,
            page: true,
            even: true,
            toolbar: "#toolbarTpl",
            size: "lg",
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: "id", title: "ID", width: 100, sort: true},
                {field: "nickname", title: "用户", width: 150},
                {field: "food_name", title: "菜品名称", width: 100},
                {field: "review_text",title: "评价",width: 220},
                {field: "review_image_url", title: "图片", width: 100,templet: "#img"},
                {field: "createdate", title: "评价时间", width: 200},
                {field: "star", title: "评分", width: 140,templet: "#star"},
                {field: "disabled", title: "状态", width: 100,templet: "#disabled"},
                {title: "操作", width: 100, align: "center", fixed: "right", templet: "#operationTpl"}
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count)
            }
        });
        form.on("submit(search)", function (data) {
            articleTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            return false;
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "batchEnabled":
                    batchEnabled();
                    break;
                case "batchDisabled":
                    batchDisabled();
                    break;
                case "batchDelete":
                    batchDelete();
                    break;
                case "add":
                    add();
                    break;
            }
        });
        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data);
                    break;
                case "deleteById":
                    deleteById(data.id);
                    break;
            }
        });

        function batchEnabled() {
            okLayer.confirm("确定要批量上架吗？", function (index) {
                layer.close(index);
                let idsStr = okUtils.tableBatchCheck(table);
                if (idsStr) {
                    okUtils.ajax("../../food.action?op=startFood", "POST", {idsStr: idsStr}, true).done(function (response) {
                        okUtils.tableSuccessMsg(response.msg);
                    }).fail(function (error) {
                        console.log(error);
                    });
                }
            });
        }

        function batchDisabled() {
            okLayer.confirm("确定要批量下架吗？", function (index) {
                layer.close(index);
                let idsStr = okUtils.tableBatchCheck(table);
                if (idsStr) {
                    okUtils.ajax("../../food.action?op=stopFood", "POST", {idsStr: idsStr}, true).done(function (response) {
                        okUtils.tableSuccessMsg(response.msg);
                    }).fail(function (error) {
                        console.log(error);
                    });
                }
            });
        }

        function batchDelete() {
            okLayer.confirm("确定要批量删除吗？", function (index) {
                layer.close(index);
                let idsStr = okUtils.tableBatchCheck(table);
                if (idsStr) {
                    okUtils.ajax("../../reviews.action?op=del", "POST", {idsStr: idsStr}, true).done(function (response) {
                        okUtils.tableSuccessMsg(response.msg);
                    }).fail(function (error) {
                        console.log(error);
                    });
                }
            });
        }

        function add() {
            okLayer.confirm("确定要一键回复评价吗？", function (index) {
                layer.close(index);
                let idsStr = okUtils.tableBatchCheck(table);
                if (idsStr) {
                    okUtils.ajax("../../reviews.action?op=reviews", "POST", {idsStr: idsStr}, true).done(function (response) {
                        okUtils.tableSuccessMsg(response.msg);
                    }).fail(function (error) {
                        console.log(error);
                    });
                }
            });
        }

        function edit(data) {
            okLayer.open("回复评价", "tb_food_pjia_return.html?id="+data.id, "90%", "90%", null, function () {
                articleTable.reload();
            })
        }
        // function updateById(id) {
        //     okLayer.open("编辑菜品", "tb_update_food.html?id=" + id, "90%", "90%", null, function () {
        //         articleTable.reload();
        //     })
        // }
        function deleteById(id) {
            okLayer.confirm("确定要删除吗？", function () {
                okUtils.ajax("../../reviews.action?op=del", "POST", {
                    "idsStr": id,
                }, true).done(function (response) {
                    okUtils.tableSuccessMsg(response.msg);
                }).fail(function (error) {
                    console.log(error);
                });
            })
        }
    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDelete">批量删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="add">一键评价回复</button>
    </div>
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    <a href="javascript:" title="编辑" lay-event="edit"><i class="layui-btn layui-btn-normal layui-btn-xs">回复</i></a>
    <a href="javascript:" title="删除" lay-event="deleteById"><i class="layui-icon">&#xe640;</i></a>
</script>

<script type="text/html" id="foodtype_id">
    {{# if(d.foodtype_id == 1) { }}
    <span class="layui-btn layui-btn-normal layui-btn-xs">主食</span>
    {{# } else if(d.foodtype_id == 2) { }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">凉菜</span>
    {{# } else if(d.foodtype_id == 3) { }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">热菜</span>
    {{# } else if(d.foodtype_id == 4) { }}
    <span class="layui-btn layui-btn-sm layui-btn-xs">饮料</span>
    {{# } else if(d.foodtype_id == 5) { }}
    <span class="layui-btn layui-btn-sm layui-btn-xs">甜点</span>
    {{# } }}
</script>
<script type="text/html" id="star">
    {{# if(d.star == 1) { }}
    <img class="layui-btn  layui-btn-xs" src="https://daiwei001.oss-cn-beijing.aliyuncs.com/1.png"/>
    {{# } else if(d.star == 2) { }}
    <img class="layui-btn  layui-btn-xs" src="https://daiwei001.oss-cn-beijing.aliyuncs.com/2.png"/>
    {{# } else if(d.star == 3) { }}
    <img class="layui-btn layui-btn-danger layui-btn-xs" src="https://daiwei001.oss-cn-beijing.aliyuncs.com/3.png"/>
    {{# } else if(d.star == 4) { }}
    <img class="layui-btn layui-btn-danger layui-btn-xs" src="https://daiwei001.oss-cn-beijing.aliyuncs.com/4.png"/>
    {{# } else if(d.star == 5) { }}
    <img class="layui-btn layui-btn-danger layui-btn-xs" src="https://daiwei001.oss-cn-beijing.aliyuncs.com/5.png"/>
    {{# } }}
</script>

<script type="text/html" id="disabled">
    {{# if(d.disabled == 0) { }}
    <span class="layui-btn layui-btn-normal layui-btn-xs">正常</span>
    {{# } else if(d.disabled == 1) { }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">不正常</span>
    {{# } }}
</script>

<script type="text/html" id="img">
    <image src="{{d.review_image_url}}"/>
</script>

<script type="text/html" id="urlTpl">
    <a href="{{d.url}}" target="_blank">{{d.url}}</a>
</script>
</body>
</html>
</html>